{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pandas import Series\n",
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 通过一维数组创建\n",
    "arr = np.array([1,3,5,np.NaN,0])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0    1.0\n",
       "1    3.0\n",
       "2    5.0\n",
       "3    NaN\n",
       "4    0.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "series0 = Series(arr)\n",
    "series0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "RangeIndex(start=0, stop=5, step=1)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "series0.index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 1.,  3.,  5., nan,  0.])"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "series0.values"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "张三    1.0\n",
       "李四    3.0\n",
       "王五    5.0\n",
       "赵六    NaN\n",
       "三宏    0.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 添加索引\n",
    "series0.index=[u'张三',u'李四',u'王五',u'赵六',u'三宏',]\n",
    "series0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "语文    85.0\n",
       "数学    88.0\n",
       "英语    90.0\n",
       "dtype: float64"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 创建时就添加索引\n",
    "series1 = Series(data=[85,88,90],dtype=np.float64,index=[u'语文',u'数学',u'英语',])\n",
    "series1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "zhangsan    78\n",
       "lisi        79\n",
       "wangwu      90\n",
       "dtype: int64"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 通过字典创建\n",
    "dic0 = {'zhangsan':78,'lisi':79,'wangwu':90}\n",
    "series2 = Series(dic0)\n",
    "series2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "zhangsan    78\n",
       "lisi        79\n",
       "wangwu      90\n",
       "Name: 生物成绩, dtype: int64"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 常见都series属性\n",
    "series2.name=u'生物成绩'\n",
    "series2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "series2[zhangsan]: 78\n",
      "series0: 78\n",
      "series-1: 90\n",
      "\n",
      "lisi      79\n",
      "wangwu    90\n",
      "Name: 生物成绩, dtype: int64\n",
      "\n",
      "lisi      79\n",
      "wangwu    90\n",
      "Name: 生物成绩, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "# Series值的获取\n",
    "print('series2[zhangsan]:',series2['zhangsan'])\n",
    "print('series0:',series2[0])\n",
    "print('series-1:',series2[-1])\n",
    "print()\n",
    "print(series2[1:])\n",
    "print()\n",
    "print(series2['lisi':'wangwu'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "张三    1.0\n",
      "李四    3.0\n",
      "王五    5.0\n",
      "赵六    NaN\n",
      "三宏    0.0\n",
      "dtype: float64\n",
      "\n",
      "张三     True\n",
      "李四     True\n",
      "王五     True\n",
      "赵六    False\n",
      "三宏     True\n",
      "dtype: bool\n",
      "\n",
      "张三    1.0\n",
      "李四    3.0\n",
      "王五    5.0\n",
      "三宏    0.0\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "# 数据筛选 isnull和notnull两个函数可以用于在Series中检测缺失\n",
    "print(series0)\n",
    "print()\n",
    "print(pd.notnull(series0))\n",
    "print()\n",
    "print(series0[pd.notnull(series0)])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
